//
//  HMNavigationController.swift
//  Weibo
//
//  Created by 吴少飞 on 16/9/19.
//  Copyright © 2016年 wushaofei. All rights reserved.
//

import UIKit

class HMNavigationController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        //边缘手势代理
        self.interactivePopGestureRecognizer?.delegate = self
    
    }

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
//        print(viewControllers.count)
        
        if viewControllers.count > 0 {
            
//            tabBarController?.tabBar.isHidden = true

            if viewControllers.count == 1 {
                
                let title = viewControllers.first?.title
                
                viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: title!, imageName: "navigationbar_back_withtext", target: self, action: #selector(backAction))
                
            }else{
                
                viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "返回", imageName: "navigationbar_back_withtext", target: self, action: #selector(backAction))
                
//                viewController.hidesBottomBarWhenPushed = true

                
            }
            viewController.title = "当前显示的第\(viewControllers.count+1)级控制器"
            
            viewController.hidesBottomBarWhenPushed = true

        }
        super.pushViewController(viewController, animated: animated)
        
    }
    //左侧按钮点击事件
    func backAction(){
        
        
        popViewController(animated: true)
        
    }
    
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        
        if viewControllers.count == 1 {
            
            return false
        }
        
        return true
    }

}
